package com.boss.salary.service.impl;

import com.boss.common.entity.PageDTO;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.dao.ISalWorkflowBackDao;
import com.boss.salary.service.IWorkflowBackConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
@Service
public class WorkflowBackConfigServiceImpl implements IWorkflowBackConfigService {
    @Autowired
    private ISalWorkflowBackDao workflowBackDao;
    @Override
    public PageDTO<Map<String, Object>> queryWorkflowBackPage(PaginationDTO paginationDTO,String province) {
        List<Map<String, Object>> menus=workflowBackDao.queryWorkflowBackPage(paginationDTO,province);
        int total=workflowBackDao.queryWorkflowBackPageCount(province);
        PageDTO<Map<String, Object>> PageDTO = new PageDTO<>();
        PageDTO.setRows(menus);
        PageDTO.setTotal(total);
        return PageDTO;
    }

    @Override
    public void insertWorkflowBack(Map<String, Object> params) {
        String menu=workflowBackDao.getBackMenuId(params.get("mof_div_code").toString(),params.get("menu_id").toString());
        if(!StringUtils.isEmpty(menu)){
            throw new RuntimeException("已配置该菜单返回节点，请勿重复配置！");
        }
        workflowBackDao.insertWorkflowBack(params);
    }

    @Override
    public void updateWorkflowBack(Map<String, Object> params) {
        String menu=workflowBackDao.getIsExist(params.get("mof_div_code").toString(),params.get("menu_id").toString(),params.get("id").toString());
        if(!StringUtils.isEmpty(menu)){
            throw new RuntimeException("已配置该菜单返回节点，请勿重复配置！");
        }
        workflowBackDao.updateWorkflowBack(params);
    }

    @Override
    public void deleteWorkflowBack(String id) {
        workflowBackDao.deleteWorkflowBack(id);
    }
}
